package com.hzjx.fenci.dao;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import com.hzjx.fenci.model.SingleWord;
import com.leisecu.common.DaoInterface;

@Service("singleWordDao")
public class SingleWordDao extends HibernateDaoSupport implements DaoInterface{

	
	@Resource(name="sessionFactory")
	public void setMySessionFactory(SessionFactory sessionFactory){
		this.setSessionFactory(sessionFactory);
		
	}
	
	public void delete(Long id) {
		SingleWord sw=(SingleWord) this.getHibernateTemplate().get(SingleWord.class, id);
		this.getHibernateTemplate().delete(sw);
	}

	public void save(Object entity) {
		this.getHibernateTemplate().saveOrUpdate(entity);
	}


	public SingleWord get(Long id) {
		return (SingleWord)this.getHibernateTemplate().get(SingleWord.class, id);
	}

	public long countAll() {
		String hql="select count(*) from SingleWord ";
		Query q= this.getSession().createQuery(hql);
		return ((Long)q.uniqueResult()).longValue();
	}

	public long countBy(String condition) {
		String hql="select count(*) from SingleWord ";
		hql=hql+condition;
		
		Query q= this.getSession().createQuery(hql);
		return ((Long)q.uniqueResult()).longValue();
	}


	
	
}
